package com.chinasoft.user.mapper;

import com.chinasoft.user.domain.Business;
import com.chinasoft.user.vo.BusinessVo;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * 商家映射接口
 */
public interface BusinessMapper {

    /**
     * 查询所有商家信息，名称，地址
     * @return
     */
    @Select("<script>select * from business" +
            "<where>" +
            "<if test='busName !=null'> bus_name like concat('%',#{busName},'%')</if>" +
            "<if test='address !=null'>or address like concat('%',#{address},'%')</if>" +
            "</where>" +
            "</script>")
    @Results(id = "BusinessVoMap",value = {
            @Result(property = "id",column = "id",id = true),
            @Result(property = "busName",column = "bus_name"),
            @Result(property = "address",column = "address"),
            @Result(property = "phone",column = "phone"),
            @Result(property = "busImage",column = "bus_image"),
            @Result(property = "dishList",column = "id",
                    many = @Many(select = "com.chinasoft.dish.mapper.DishMapper.findOne",fetchType = FetchType.DEFAULT))
    })
    List<BusinessVo> findAll(BusinessVo vo);



    @Select("select * from business where account = #{account}")
    Business findOne(String account);
}
